<!DOCTYPE html>
<html lang="en">
<head>
    <base href="${basePath}">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>批分部门</title>
    <link rel="stylesheet" href="${basePath}static/ztc/css/base.css">
    <link rel="stylesheet" href="${basePath}static/ztc/css/main.css">
    <link rel="stylesheet" type="text/css" href="${basePath}static/ztc/css/uiGroup.css">
    <script type="text/javascript" src="${basePath}static/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="${basePath}static/jquerysession.js"></script>
    <script type="text/javascript" src="${basePath}static/store.js"></script>
    <script type="text/javascript" src="${basePath}static/ztc/js/myjs/global.js"></script>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            min-width: auto;
        }
    </style>
</head>


<body>

<div id="selectPart" class="dialogContent">
    <div class="label">选择部门：</div>
    <#list depts?if_exists  as systemDt>
        <div class="department fl " style="width: 50%;text-align: left">
            <input class="depart" type="checkbox" name="depart" id = "depart" deptname="${systemDt.name!}" value="${systemDt.id}" />
             ${systemDt.name!}
            <span class="hide islead"><input id="islead" type="radio" name="isLead" value=""/>牵头部门</span>
        </div>
    </#list>
</div>
<div class="btn_group fixed" style="background: #fff">
    <button class="submitBtn redBtn" id="SelectDept" >确定</button>
    <button class="submitBtn redBtn" onclick="top.Dialog.close()">取消</button>
</div>
</body>
</html>
<script type="text/javascript">

    $(function(){
        $(".department .depart").bind("click",function () {
            if ( $(this).is(":checked")) {
                if($("input[name='depart']:checked").size()==1){//第一个选中的机构默认是主办行
                    $(this).siblings('.islead').children().attr("checked", "checked");
                }
                $(this).siblings('.islead').show();
            }else{
                $(this).siblings('.islead').hide();
            }
        });

        $("#SelectDept").bind("click",function () {

            var deptArray = new Array();
            /**
             * 清楚session中的批分机构
             */
            if($("input[name='depart']:checked").length==0){
                window.parent.$("#listBranchTit").hide();
            }
            $("input[name='depart']:checked").each(function() {

                    var isMaster="1";//不是主办行
                    if($(this).siblings('.islead').children().attr("checked")){
                        isMaster = "0";
                    }
                    var branch = {name:$(this).attr("deptname"),id:$(this).val(),isMaster:isMaster};
                    deptArray.push(branch);
              //  }

            })
            store.set(Constant.DEPT_PF, JSON.stringify(deptArray));
           // $.session.set(Constant.DEPT_PF, JSON.stringify(deptArray));//JSON.stringify 把Json对象转换成字符串
            top.Dialog.close();
        });
    })

</script>